<?php
class Myh_Validate_NotEmpty extends Zend_Validate_Abstract
{
	const INVALID  = 'notEmptyInvalid';
	
	const IS_EMPTY = 'isEmpty';
	
	protected $_messageTemplates = array();
	
	protected $_type =  'strNormal';
	
	public function __construct($options=null)
	{
		if($options!=null){
			$this->_messageTemplates[self::IS_EMPTY] 	= $options['msgErrorEmpty'];
			if($options['msgErrorInvalid']){
				$this->_messageTemplates[self::INVALID] 	= $options['msgErrorInvalid'];
			}
			if($options['type']){
				$this->_type = $options['type'];
			}
		}else{
			$this->_messageTemplates[self::IS_EMPTY] = "Value is required and can't be empty";
			$this->_messageTemplates[self::INVALID]  = 'Value is invalid';
		}
	}
	public function isValid($value)
	{
		if (is_string($value) && (preg_match('/^\s+$/s', $value))) {
           	$this->_error(self::IS_EMPTY);
            return false;
        }
		if (is_null($value)) {
            $this->_error(self::IS_EMPTY);
            return false;
        }
		if (is_string($value) && ($value == '')) {
            $this->_error(self::IS_EMPTY);
            return false;
       	}
		if ($this->_type != 'strNormal') {
			if(preg_match("#^[a-zA-Z0-9]+[\.\-\_]?[a-zA-Z0-9]+$#", $value)){
				$this->_error(self::INVALID);
            	return false;
			}
            
       	}
	}
}